package com.itheima.webserver.controller;


import cn.hutool.core.date.DateUtil;
import com.itheima.commons.model.vo.DashboardDistributionVo;
import com.itheima.commons.model.vo.DashboardSummaryVo;
import com.itheima.commons.model.vo.DashboardUsersVo;
import com.itheima.webserver.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/*
 * @ProjectName:project-exercise
 * @Package:com.itheima.webserver.controller
 * @ClassName:DashboardController
 * @Author:ZHANG
 * @Date:2021-12-16 20:14
 * @Description:
 */
@RestController
@RequestMapping("dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    /*
     * @MethodName:dashboardDistribution
     * @ParamType:[java.util.Date, java.util.Date]
     * @Param:[startDate, endDate]
     * @Exception:
     * @Return:dashboardVo
     * @Description:注册用户分布，行业top、年龄、性别、地区
     */
    @GetMapping("distribution")
    public ResponseEntity dashboardDistribution(@RequestParam(value = "sd")  Long sDate,
                                                @RequestParam(value = "ed")  Long eDate) {
        String startDate = DateUtil.date(sDate).toString("yyyy-MM-dd");
        String endDate = DateUtil.date(eDate).toString("yyyy-MM-dd");
        DashboardDistributionVo dashboardDistributionVo = dashboardService.dashboardDistribution(startDate, endDate);
        return ResponseEntity.ok(dashboardDistributionVo);
    }

    /* 
     * @MethodName:queryUsersAddActiveRetentionRate
     * @ParamType:[java.util.Date, java.util.Date, java.lang.String]
     * @Param:[startDate, endDate, type]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:新增、活跃用户、次日留存率
     */
    @GetMapping("users")
    public ResponseEntity queryUsersAddActiveRetentionRate(@RequestParam(value ="sd")  Long sDate,
                                                           @RequestParam(value ="ed")  Long eDate,
                                                           @RequestParam(value ="type") String type) {
        String startDate = DateUtil.date(sDate).toString("yyyy-MM-dd");
        String endDate = DateUtil.date(eDate).toString("yyyy-MM-dd");
        DashboardUsersVo dashboardUsersVo = dashboardService.queryUsersAddActiveRetentionRate(startDate, endDate, type);

        return ResponseEntity.ok(dashboardUsersVo);
    }

    /* 
     * @MethodName:queryOverviewStatistics
     * @ParamType:[]
     * @Param:[]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:概要统计信息
     */
    @GetMapping("summary")
    public ResponseEntity queryOverviewStatistics() {
        DashboardSummaryVo dashboardSummaryVo = dashboardService.queryOverviewStatistics();
        return ResponseEntity.ok(dashboardSummaryVo);
    }


}
